package com.cjhedu.web.config;

/**
 * @author 陈佳豪
 * @version 1.0
 */
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:90") // 生产环境建议替换为前端实际域名（如 "http://localhost:3000"）
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 加上OPTIONS
                .allowedHeaders("*")
                .exposedHeaders("Authorization")
                .allowCredentials(true); // 注意：allowCredentials(true)时，allowedOrigins不能为*
    }
}
